//
//  RectangleLayer.swift
//  QBLaunchAnimation
//
//  Created by 乐启榜 on 16/8/26.
//  Copyright © 2016年 乐启榜. All rights reserved.
//

import UIKit

class RectangleLayer: CAShapeLayer {

    override init() {
        super.init()
        fillColor = UIColor.clearColor().CGColor
        lineWidth = 3.0
        path = rectangleFullPath.CGPath
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var rectangleFullPath: UIBezierPath {
        let fullPath = UIBezierPath()
        fullPath.moveToPoint(CGPointMake(0.0, 100.0))
        fullPath.addLineToPoint(CGPointMake(0.0, -lineWidth))
        fullPath.addLineToPoint(CGPointMake(100.0, -lineWidth))
        fullPath.addLineToPoint(CGPointMake(100.0, 100.0))
        fullPath.addLineToPoint(CGPointMake(-lineWidth / 2, 100.0))
        fullPath.closePath()
        return fullPath
    }
    
    func strokeChangeWithColor(color: UIColor){
        strokeColor = color.CGColor
        let strokeAnimation: CABasicAnimation = CABasicAnimation(keyPath: "strokeEnd")
        strokeAnimation.fromValue = 0.0
        strokeAnimation.toValue = 1.0
        strokeAnimation.duration = 0.4
        addAnimation(strokeAnimation, forKey: nil)
    }

}
